package org.grottarossa.ui.core.i18n;

import java.io.File;
import java.util.HashMap;
import java.util.Locale;
import java.util.ResourceBundle;

//Dictionary Manager
public class DM
{
	private static DM _instance;

	String language = "it";
	String country = "IT";

	Locale locale;

	HashMap<String, ResourceBundle> vResources = new HashMap<String, ResourceBundle>();

	private DM(String language, String country)
	{
		this.language = language;
		this.country = country;
		locale = new Locale(language, country);
	}

	//read all properties files
	private void initialize()
	{
		String sPath = String.format("%s", getClass().getResource(DM.class.getName()).getPath());
		File dir = new File(sPath);
		String[] children = dir.list();

		if (children != null) {
		    for (int i=0; i<children.length; i++)
		    {
		    	ResourceBundle bundle = ResourceBundle.getBundle(children[i].replace(".properties", ""),locale);
		    	vResources.put(children[i].replace(".properties", ""), bundle);
		    }
		}
	}

	public static DM instance()
	{
		if(_instance==null)
		{
			synchronized(DM.class)
			{
				if(_instance==null)
					_instance = new DM("it", "IT");
			}
		}
		return _instance;
	}

	public ResourceBundle getBundle(String sPrefix)
	{
		return ResourceBundle.getBundle(sPrefix, locale);
	}

}